// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 * Creator: yanking
 * Create time: 2022-01-30 09:44
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.measurePerf;

import java.util.function.Function;

public class measureUtils {
    // This is a measure class to test a function's fastest running time
    public static long measurePerf(Function<Long, Long> adder, long n) {
        long fastest = Long.MAX_VALUE;
        long start = System.nanoTime();
        for (int i = 0; i < 10; i++) {
            long sum = adder.apply(n);
            long duration = (System.nanoTime() - start) / 1_000_000;
            System.out.println("Result:" + sum);
            if (duration < fastest) fastest = duration;
        }
        return fastest;
    }

}
